<?php
	
	class Mailer
	{
		private static $sInstance;
		private $oMailer;
		
		private function __construct()
		{
			require_once $_SERVER["DOCUMENT_ROOT"] . "/private/phpmailer/class.phpmailer.php";
			
			$this->oMailer = new PHPMailer(true);
			$this->oMailer->IsSMTP();
			
			$this->oMailer->SMTPDebug = 0;
			$this->oMailer->SMTPAuth = MAIL_AUTH;
			$this->oMailer->Port = MAIL_PORT;
			$this->oMailer->Username = MAIL_USERNAME;
			$this->oMailer->Password = MAIL_PASSWORD;
			$this->oMailer->AddReplyTo(MAIL_FROM, MAIL_USERNAME);
			$this->oMailer->SetFrom(MAIL_FROM, MAIL_USERNAME);
		}
		private function __clone() {}
		
		public static function &i()
		{
			if (is_null(self::$sInstance) || !is_object(self::$sInstance))
				self::$sInstance = new self();
			
			return self::$sInstance;
		}
		
		public function send($to, $subject, $content)
		{
			$this->oMailer->Subject = htmlspecialchars($subject);
			
			try
			{
				$this->oMailer->AddAddress($to); 
				$this->oMailer->MsgHTML($content);
				$this->oMailer->Send();
				return true;
			}
			catch (phpmailerException $e)
			{
				die("Fail to send mail: <br>" . $e->getMessage());
				return false;
			}
		}
	}
?>